//
//  InputLogViewController.m
//  Juejue
//
//  Created by 吴军虎吴军虎 on 16/3/22.
//  Copyright © 2016年 lanjue. All rights reserved.
//

#import "InputLogViewController.h"


@interface InputLogViewController ()<UITextFieldDelegate>

//@property (nonatomic,retain) UIView *myheaderView;
@property (nonatomic,retain) UIButton *goBack;
@property (nonatomic,retain) UITextField *chinalabel;
@property (nonatomic,retain) UITextField *loginlabel;
@property (nonatomic,retain) UITextField *againlabel;

@end

@implementation InputLogViewController

-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden=YES;
    self.title=@"修改密码";
}

- (void)viewWillDisappear:(BOOL)animated {
    
    self.navigationController.navigationBarHidden = NO;
     self.tabBarController.tabBar.hidden=NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=LV;

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
 
    
    //白框
    UIView *baiView=[[UIView alloc]init];
    baiView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:baiView];
    [baiView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.view.mas_top).offset(60/2 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(0);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 87/2 *AUTO_HEIGHT));
    }];
    
    
    //原密码
    UILabel *yulabel=[[UILabel alloc]init];
    yulabel.text=@"原密码";
    yulabel.textColor=HS;
    yulabel.font=[UIFont systemFontOfSize:15];
    [baiView addSubview:yulabel];
    [yulabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(baiView.mas_top).offset(25 /2 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(15 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(60 *AUTO_WIDTH, 20 *AUTO_HEIGHT));
        
    }];
    
    _chinalabel=[[UITextField alloc]init];
    _chinalabel.placeholder=@"请输入原密码";
    _chinalabel.delegate=self;
    _chinalabel.textColor=[UIColor blackColor];
    _chinalabel.textAlignment=NSTextAlignmentLeft;
    _chinalabel.font=[UIFont systemFontOfSize:14];
    _chinalabel.secureTextEntry=YES;
    [baiView addSubview:_chinalabel];
    [_chinalabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(baiView.mas_top).offset(16/2 *AUTO_HEIGHT);
        make.left.equalTo(yulabel.mas_right).offset(18/2*AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(280 *AUTO_WIDTH, 30 *AUTO_HEIGHT));
    }];
    
    
    //横线
    UILabel *henglabel=[[UILabel alloc]init];
    henglabel.backgroundColor=[UIColor grayColor];
    henglabel.alpha=0.3;
    [self.view addSubview:henglabel];
    [henglabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(baiView.mas_top).offset(0);
        make.left.mas_equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 1 *AUTO_WIDTH));

    }];
    
    
    //横线
    UILabel *henglabel1=[[UILabel alloc]init];
    henglabel1.backgroundColor=[UIColor grayColor];
    henglabel1.alpha=0.3;
    [self.view addSubview:henglabel1];
    [henglabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView.mas_bottom).offset(0);
        make.left.mas_equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 1 *AUTO_WIDTH));
        
    }];
    

    //第二白框
    UIView *baiView1=[[UIView alloc]init];
    baiView1.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:baiView1];
    [baiView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView.mas_bottom).offset(30/2 *AUTO_WIDTH);
        make.left.equalTo(self.view).offset(0);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 87/2 *AUTO_HEIGHT));
    }];
    
    
    //新密码
    UILabel *xinlabel=[[UILabel alloc]init];
    xinlabel.text=@"新密码";
    xinlabel.textColor=HS;
    xinlabel.font=[UIFont systemFontOfSize:15];
    [baiView1 addSubview:xinlabel];
    [xinlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView1.mas_top).offset(25 /2 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(15 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(60 *AUTO_WIDTH, 20 *AUTO_HEIGHT));
        
    }];
    
    _loginlabel=[[UITextField alloc]init];
    _loginlabel.placeholder=@"请设置登录密码";
    _loginlabel.delegate=self;
    _loginlabel.textColor=[UIColor blackColor];
    _loginlabel.textAlignment=NSTextAlignmentLeft;
    _loginlabel.font=[UIFont systemFontOfSize:14];
    _loginlabel.secureTextEntry=YES;
    [baiView1 addSubview:_loginlabel];
    [_loginlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView1.mas_top).offset(16/2 *AUTO_HEIGHT);
        make.left.equalTo(xinlabel.mas_right).offset(18/2*AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(280 *AUTO_WIDTH, 30 *AUTO_HEIGHT));
    }];
    
    
    //横线
    UILabel *henglabel2=[[UILabel alloc]init];
    henglabel2.backgroundColor=[UIColor grayColor];
    henglabel2.alpha=0.3;
    [self.view addSubview:henglabel2];
    [henglabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView1.mas_top).offset(0);
        make.left.mas_equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 1 *AUTO_WIDTH));
        
    }];
    
    
    //横线
    UILabel *henglabel3=[[UILabel alloc]init];
    henglabel3.backgroundColor=[UIColor grayColor];
    henglabel3.alpha=0.1;
    [self.view addSubview:henglabel3];
    [henglabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView1.mas_bottom).offset(0);
        make.left.mas_equalTo(self.view).offset(15 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 1 *AUTO_WIDTH));
        
    }];
    
    
    //第三白框
    UIView *baiView2=[[UIView alloc]init];
    baiView2.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:baiView2];
    [baiView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(henglabel3.mas_bottom).offset(0);
        make.left.equalTo(self.view).offset(0);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 87/2 *AUTO_HEIGHT));
    }];
    

    //新密码
    UILabel *quelabel=[[UILabel alloc]init];
    quelabel.text=@"确认密码";
    quelabel.textColor=HS;
    quelabel.font=[UIFont systemFontOfSize:15];
    [baiView2 addSubview:quelabel];
    [quelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView2.mas_top).offset(25 /2 *AUTO_HEIGHT);
        make.left.equalTo(self.view).offset(15 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(60 *AUTO_WIDTH, 20 *AUTO_HEIGHT));
        
    }];
    
    _againlabel=[[UITextField alloc]init];
    _againlabel.placeholder=@"再次输入密码";
    _againlabel.delegate=self;
    _againlabel.textColor=[UIColor blackColor];
    _againlabel.textAlignment=NSTextAlignmentLeft;
    _againlabel.font=[UIFont systemFontOfSize:14];
    _againlabel.secureTextEntry=YES;
    [baiView2 addSubview:_againlabel];
    [_againlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView2.mas_top).offset(16/2 *AUTO_HEIGHT);
        make.left.equalTo(quelabel.mas_right).offset(18/2*AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(280 *AUTO_WIDTH, 30 *AUTO_HEIGHT));
    }];
    
    
    //横线
    UILabel *henglabel4=[[UILabel alloc]init];
    henglabel4.backgroundColor=[UIColor grayColor];
    henglabel4.alpha=0.3;
    [self.view addSubview:henglabel4];
    [henglabel4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(baiView2.mas_bottom).offset(0);
        make.left.mas_equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 1 *AUTO_WIDTH));
        
    }];
    

    
    //确定修改手机号码
    UIButton *Dview=[[UIButton alloc]init];
    Dview.backgroundColor=GH;
    Dview.layer.cornerRadius=5;
    [Dview setTitle:@"修改密码" forState:UIControlStateNormal];
    [Dview setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    Dview.titleLabel.font=[UIFont fontWithName:@"Arial" size:LOGINFONT *TEXTWEIGHT];
    [Dview addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Dview];
    [Dview mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(baiView2.mas_bottom).offset(180/2 *AUTO_WIDTH);
        make.left.equalTo(self.view.mas_left).offset(44/2 *AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width-88/2 *AUTO_WIDTH, 78/2 *AUTO_WIDTH));
    }];
    
    

    
}
    
    
//返回上一页
-(void)Back:(UIButton *)goback{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


-(void) btnClick:(UIButton *) btn
{
    NSLog(@"修改按钮被点击了");
}

#pragma mark -设置textField的长度
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField ==_chinalabel) {
        
        if (textField.text.length <=25) {
            
            if (range.location ==25) {
                
                return NO;
            }else if (range.location ==0){
                
                NSMutableString *str=[[NSMutableString alloc]initWithString:textField.text];
                
                if (range.location != NSNotFound) {
                    
                }else{
                    
                    
                    textField.text=str;
                }
                return YES;
            }else if (range.location ==0){
                
                NSMutableString *str=[[NSMutableString alloc]initWithString:textField.text];
                NSString *str1;
                str1=[str stringByReplacingOccurrencesOfString:@"-" withString:@""];
                textField.text=str1;
                return YES;
            }else {
                
                return YES;
                
            }
            return NO;
        }
        
    }if (textField ==_loginlabel) {
        
        if (textField.text.length <=25) {
            
            if (range.location ==25) {
                
                return NO;
            }else if (range.location ==0){
                
                NSMutableString *str=[[NSMutableString alloc]initWithString:textField.text];
                
                if (range.location != NSNotFound) {
                    
                }else{
                    
                    
                    textField.text=str;
                }
                return YES;
            }else if (range.location ==0){
                
                NSMutableString *str=[[NSMutableString alloc]initWithString:textField.text];
                NSString *str1;
                str1=[str stringByReplacingOccurrencesOfString:@"-" withString:@""];
                textField.text=str1;
                return YES;
            }else {
                
                return YES;
                
            }
            return NO;
        }
    }
    if (textField == _againlabel) {
        
        if (textField.text.length <=25) {
            
            if (range.location ==25) {
                
                return NO;
            }else if (range.location ==0){
                
                NSMutableString *str=[[NSMutableString alloc]initWithString:textField.text];
                
                if (range.location != NSNotFound) {
                    
                }else{
                    
                    
                    textField.text=str;
                }
                return YES;
            }else if (range.location ==0){
                
                NSMutableString *str=[[NSMutableString alloc]initWithString:textField.text];
                NSString *str1;
                str1=[str stringByReplacingOccurrencesOfString:@"-" withString:@""];
                textField.text=str1;
                return YES;
            }else {
                
                return YES;
                
            }
            return NO;
        }
    }

    return NO;
   
}


@end

